﻿<div class="d-flex">
    <MudButton OnClick="OpenDialog" Variant="Variant.Filled" Color="Color.Primary">
        Show Dialog
    </MudButton>
</div>

<MudDialog @bind-Visible="DialogVisible" Options="_dialogOptions">
    <TitleContent>
        <MudText Typo="Typo.h6">
            @DialogTitle
        </MudText>
    </TitleContent>
    <DialogContent>
        <MudProgressLinear Color="Color.Primary" Striped="true" Size="Size.Large" Class="my-7" Value="@DialogProgress" />
    </DialogContent>
</MudDialog>

@code {
    public static string __description__ = "Dialog title should update along with Progress Bar content";

    private readonly DialogOptions _dialogOptions = new() { FullWidth = true };
    private int DialogProgress { get; set; } = 0;
    private bool DialogVisible { get; set; } = false;
    private string DialogTitle { get; set; } = "Initial state";

    private async Task OpenDialog()
    {
        DialogVisible = true;

        for (int i = 0; i <= 10; i++)
        {
            await Task.Delay(150); // Simulate some work
            DialogProgress = i * 10; // Simulate progress update
            DialogTitle = $"Progress: {DialogProgress}%";
            StateHasChanged();
        }

        // Keep dialog open for a bit to observe final title
        await Task.Delay(2000);

        DialogVisible = false;
        DialogProgress = 0;
        DialogTitle = "Initial state";
    }
}
